package com.usian.controller;

import com.usian.User;
import com.usian.UserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/consumer")
public class ConsumerController {

    @Autowired
    private LoadBalancerClient loadBalancerClient;

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private UserFeign userFeign;

    /*@RequestMapping("/findById/{id}")
    public User findById(@PathVariable Integer id){
        ServiceInstance choose = loadBalancerClient.choose("ribbon-provider");

        String url = "http://"+choose.getHost()+":"+choose.getPort()+"/user/findById/"+id;

        return restTemplate.getForObject(url,User.class);
    }*/

    @RequestMapping("/findById/{id}")
    public User findById(@PathVariable Integer id){

        return userFeign.findById(id);
    }
}
